import os
import sys
import polars as pl
from util.sqlite_database import SQLite

base_path = os.path.dirname(os.path.realpath(sys.argv[0]))

# 读取配置文件
config_df = (
    pl.read_excel(
        os.path.join('D:/配置文件.xlsx'),
        sheet_name=["模板1", "模板2"],
        columns=["表名", "原字段名", "现字段名"],
    )
)

# 读取其它配置文件
config_other_df = (
    pl.read_excel(
        os.path.join('D:/配置文件.xlsx'),
        sheet_name="其它配置",
        columns=["key", "value"],
        schema_overrides={"value": pl.String},  # 覆盖默认的列类型
    )
    .fill_null('')
)
recipient_email = config_other_df.filter(pl.col("key")=="recipient_email")["value"].item(0) # 收件人邮箱
pdf_path = os.path.abspath(config_other_df.filter(pl.col("key")=="pdf_path")["value"].item(0)) # pdf共享盘路径
db_path = os.path.abspath(config_other_df.filter(pl.col("key")=="db_path")["value"].item(0)) # sqlite文件路径
MaximumAttachmentSize = int(config_other_df.filter(pl.col("key")=="MaximumAttachmentSize")["value"].item(0)) | 0 # 附件大小限制
sqlite = SQLite(db_path)
